package edu.bit.water.controller;

import edu.bit.water.entity.*;
import edu.bit.water.service.EntityClassifiedStandardService;
import org.apache.ibatis.reflection.MetaClass;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/entity_classified_standard")
public class EntityClassifiedStandardController {

    @Autowired
    private EntityClassifiedStandardService entityClassifiedStandardService;

    /**
     * 查询Entity_classified_standard中的记录
     * @return Entity_classified_standard中的所有记录
     */
    @RequestMapping("/select")
    @ResponseBody
    public Map<String, Object> select(){
        Map<String, Object> modelMap = new HashMap<>();
        List<EntityClassifiedStandard> list = entityClassifiedStandardService.select();
        modelMap.put("status", "success");
        modelMap.put("rows", list);
        return modelMap;
    }

    /**
     * @param entityClassifiedStandard 标签记录实体
     * @return 成功返回1,失败返回0
     */
    @RequestMapping("/insert")
    @ResponseBody
    public Map<String, String> insert(EntityClassifiedStandard entityClassifiedStandard){
        return entityClassifiedStandardService.insert(entityClassifiedStandard);
    }

    /**
     * 更新记录
     * @param entityClassifiedStandard 标签记录实体
     * @return 成功返回1,失败返回0
     */
    @RequestMapping("/update")
    @ResponseBody
    public Map<String, String> update(EntityClassifiedStandard entityClassifiedStandard){
        return entityClassifiedStandardService.update(entityClassifiedStandard);
    }

    /**
     * 删除记录
     * @param ids 删除记录的标识符
     * @return 成功返回1,失败返回0
     */
    @RequestMapping("/delete")
    @ResponseBody
    public Map<String, Object> delete(@RequestBody List<Integer> ids){
        Map<String, Object> modelMap = new HashMap<>();
        int n = entityClassifiedStandardService.delete(ids);
        if(n == 1) {
            modelMap.put("status", "success");
        }
        else
            modelMap.put("status", "failed");
        return modelMap;
    }

    /**
     * 查询META_CLASSIFIED_STANDARD中的记录
     * @return 标签表中的所有记录
     */
    @RequestMapping("/get_eva_basis")
    @ResponseBody
    public Map<String, Object> getBasis(){
        Map<String, Object> modelMap = new HashMap<>();
        List<MetaClassifiedStandard> list = entityClassifiedStandardService.getBasis();
        modelMap.put("status", "success");
        modelMap.put("rows", list);
        return modelMap;
    }

    /**
     * 查询meta_classified_standard中的标准状态
     * @return meta_classified_standard中的所有记录
     */
    @RequestMapping("/get_standard_status")
    @ResponseBody
    public Map<String, Object> getStandardStatus(){
        Map<String, Object> modelMap = new HashMap<>();
        List<MetaClassifiedStandard> list = entityClassifiedStandardService.getStandardStatus();
        modelMap.put("status", "success");
        modelMap.put("rows", list);
        return modelMap;
    }
}